package com.recursivechaos.gamemaster.dao;

import java.util.List;
import java.util.Random;

import com.recursivechaos.gamemaster.classes.CharObj;
import com.recursivechaos.gamemaster.exception.GameException;

public class MonsterNameDAO extends DAO {
	/**
	 * Get a List<String> of available monsterNames
	 * 
	 * @return List<String> of races
	 */
	@SuppressWarnings("unchecked")
	private List<String> getMonsterNameList() {
		List<String> nameList = null;
		try {
			begin();
			nameList = getSession().createSQLQuery(
					"SELECT NAME_TEXT FROM recursi3_igm_db.monsternames;")
					.list();
			commit();
		} catch (Exception e) {
			rollback();
		} finally {
			close();
		}
		return nameList;
	}

	/**
	 * Get a random race
	 * 
	 * @return RaceObj of a random race
     *
	 */
	public String getRandomName() {
		List<String> nameList = getMonsterNameList();
		String mName = "default";
		Random generator = new Random();
		int r = generator.nextInt(nameList.size());
		mName = nameList.get(r).toString();
		return mName;
	}

	/**
	 * Turns regular character into a monster
	 * 
	 * @param monster
	 *            charObj to become monster
	 * @throws GameException
	 *             Zombies?
	 */
	public void makeMonster(CharObj monster) throws GameException {
		try {
			begin();
			monster.setType("monster");
			getSession().update(monster);
			commit();
		} catch (Exception e) {
			rollback();
			throw new GameException("Was not able to monsterize the character.");
		}
	}

}
